/********************************************************************
Crytek Source File.
Copyright (C), Crytek Studios, 2001-2009.
-------------------------------------------------------------------------
File name:   AIAbstractDebugRenderer.h
$Id$
Description: Base class for AI debug renderers

-------------------------------------------------------------------------
History:
- 2009-07-02   : Created by Evgeny Adamenkov

*********************************************************************/

#ifndef _AI_ABSTRACT_DEBUG_RENDERER_H_
#define _AI_ABSTRACT_DEBUG_RENDERER_H_

#if _MSC_VER > 1000
#pragma once
#pragma warning(disable: 4800)	// No warning when deserializing int8 back to bool
#endif

#include "IAIDebugRenderer.h"
#include "INotificationNetwork.h"

#include <map>
#include <stack>


namespace
{
	//////////////////////////////////////////////////////////////////////////
	//
	//	The first byte of the serialized draw command encodes its type

	enum EDrawCommandType
	{
		eDrawAABB,
		eDrawAABB_matrix,
		eDrawArrow,
		eDrawCapsuleOutline,
		eDrawCircleOutline,
		eDrawCircles,
		eDrawCone,
		eDrawCylinder,
		eDrawEllipseOutline,
		eDraw2dLabelSimple,
		eDraw2dLabel,
		eDraw3dLabel,
		eDraw3dLabelEx,
		eDraw2dImage,
		eDrawLine,
		eDrawOBB_matrix,
		eDrawOBB_vector,
		eDrawPolyline_single_color,
		eDrawPolyline_multiple_colors,
		eDrawRangeArc,
		eDrawRangeBox,
		eDrawRangeCircle,
		eDrawRangePolygon,
		eDrawSphere,
		eDrawTriangle,
		eDrawTriangles,
		eDrawWireFOVCone,
		eDrawWireSphere,
		eLoadTexture,
		eProjectToScreen,
		eSetFlags,
		eSetMaterialColor,
		eTextToScreen,
		eTextToScreenColor,
	};


	//////////////////////////////////////////////////////////////////////////
	//
	//	Network representation of used types

	template <typename T> struct SerialTypeOf                        { };
	template <>           struct SerialTypeOf<AABB>                  { typedef AABB     type; };
	template <>           struct SerialTypeOf<bool>                  { typedef int8     type; };
	template <>           struct SerialTypeOf<ColorB>                { typedef ColorB   type; };
	template <>           struct SerialTypeOf<EBoundingBoxDrawStyle> { typedef int8     type; };
	template <>           struct SerialTypeOf<EDrawCommandType>      { typedef int8     type; };
	template <>           struct SerialTypeOf<float>                 { typedef f32      type; };
	template <>           struct SerialTypeOf<int>                   { typedef int32    type; };
	template <>           struct SerialTypeOf<Matrix34>              { typedef Matrix34 type; };
	template <>           struct SerialTypeOf<OBB>                   { typedef OBB      type; };
	template <>           struct SerialTypeOf<uint32>                { typedef uint32   type; };
	template <>           struct SerialTypeOf<Vec3>                  { typedef Vec3     type; };

	typedef SerialTypeOf<uint32>::type SerialSizeT;
}	// namespace


//////////////////////////////////////////////////////////////////////////////////////////////////
//
//	CAIAbstractDebugRenderer - the parent for CAINetworkDebugRenderer and CAIVisualDebugRenderer


class CAIAbstractDebugRenderer : public IAIDebugRenderer
{
public:
	CAIAbstractDebugRenderer() { m_stackFlags.push(SAuxGeomRenderFlags(0)); }

	virtual float GetDebugDrawZ(const Vec3& vPoint, bool bUseTerrainOrWater);

	virtual void Init2DMode() { SetFlags(e_Def2DPublicRenderflags); }
	virtual void Init3DMode() { SetFlags(e_Def3DPublicRenderflags); }

	virtual void SetAlphaBlended(bool bOn);
	virtual void SetBackFaceCulling(bool bOn);
	virtual void SetDepthTest(bool bOn);
	virtual void SetDepthWrite(bool bOn);
	virtual void SetDrawInFront(bool bOn);

	virtual uint32 PopState();
	virtual uint32 PushState();

	// The descendants need not normally override GetFlags()
	virtual SAuxGeomRenderFlags GetFlags();

	// The descendants can override SetFlags() but these implementations
	// should call CAIAbstractDebugRenderer::SetFlags
	virtual void SetFlags(SAuxGeomRenderFlags flags);

	static const char* szNetworkChannelName;


private:

	std::stack<SAuxGeomRenderFlags> m_stackFlags;


protected:

	//////////////////////////////////////////////////////////////////////////
	//
	//	Support for serialization/deserialization of LoadTexture/DrawImage

	std::map<int, int>   m_mapActualTextureID;
};


#endif	// #ifndef _AI_ABSTRACT_DEBUG_RENDERER_H_
